package com.ccom.redis.receiver;


import cn.hutool.core.util.ObjectUtil;
import com.ccom.core.common.model.BaseMap;
import com.ccom.redis.constant.GlobalConstants;
import com.ccom.redis.listener.CcomRedisListerer;
import com.ccom.tools.common.util.SpringContextHolder;
import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * 默认redis监听类
 **/
@Data
@Component
public class RedisReceiver implements RedisReceiverApi{

    /**
     * 接受消息并调用业务逻辑处理器
     *
     * @param params
     */
    @Override
    public void onMessage(BaseMap params) {
        Object handlerName = params.get(GlobalConstants.HANDLER_NAME);
        CcomRedisListerer messageListener = SpringContextHolder.getHandler(handlerName.toString(), CcomRedisListerer.class);
        if (ObjectUtil.isNotEmpty(messageListener)) {
            messageListener.onMessage(params);
        }
    }

}
